package com.etlmaster.executor.steps.func;



import com.etlmaster.executor.Step;
import com.etlmaster.executor.StepMeta;
import com.etlmaster.executor.annotation.StepInstruction;
import com.etlmaster.executor.utils.StepState;

/**
 * @author Wugf
 * @date 2016-03-08
 */
@StepInstruction("explosion")
public class ExplosionStep extends Step{

	private ExplosionStepMeta meta;
	
	public ExplosionStep(StepMeta meta) {
		super(meta);
		this.meta=(ExplosionStepMeta) meta;
		
	}

	@Override
	protected int handle() {
		Runnable runnable = new Runnable() {
			public void run() {
				try {
					meta.log("INFO","程序倒计时开始，将在{}分钟后强行退出",meta.getHour());
					Thread.sleep(Integer.parseInt(meta.getHour())*1000*60);
					meta.log("INFO","程序倒计时结束，强行退出");
				} catch (NumberFormatException e) {
					meta.log("ERROR",e.getMessage());
					e.printStackTrace();
				} catch (InterruptedException e) {
					meta.log("ERROR",e.getMessage());
					e.printStackTrace();
				}catch (Exception e) {
					meta.log("ERROR",e.getMessage());
					e.printStackTrace();
				}finally{

					System.exit(Integer.parseInt(meta.getId()));
				}
			}
		};
		new Thread(runnable).start();
		return StepState.RUNNING_SUCCESSED;
	}

	@Override
	public boolean stop() {
		
		return false;
	}

}
